package com.caifu.controller.baseData;

import com.caifu.controller.AbstractController;
import com.caifu.pojo.SysUser;
import com.caifu.pojo.YlRoom;
import com.caifu.service.IRoomService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* 
* 功能描述：房间管理
*
* @Author  GZ
* @Date   2020/11/8 16:00
*/
@Controller
@RequestMapping("/baseData/room")
public class RoomController extends AbstractController {

    @Autowired
    private IRoomService roomService;

    /**
    * 
    * 功能描述：跳转到房间列表
    *
    * @Author  GZ
    * @Date   2020/11/8 16:01
    */
    @RequestMapping("roomList")
    public String roomList(String floorNo, Model model){
        try {
            JSONObject floorInfo =roomService.queryFloorInfo(floorNo);
            model.addAttribute("floorInfo",floorInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "baseData/roomList";
    }

    /**
     *
     * 功能描述：查询房间数据信息
     *
     * @Author  GZ
     * @Date   2020/11/8 10:04
     */
    @RequestMapping("obtainRoomData")
    @ResponseBody
    public JSONObject obtainFloorData(String floorNo){
        try {
            return roomService.queryRoomData(floorNo);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     * 功能描述：保存房间信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:46
     */
    @RequestMapping("saveRoomInfo")
    @ResponseBody
    public JSONObject saveRoomInfo(YlRoom room){
        try {
            SysUser user =getUser();
            return roomService.saveRoomInfo(room,user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *
     * 功能描述：查询房间信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:46
     */
    @RequestMapping("queryRoomInfo")
    @ResponseBody
    public JSONObject queryRoomInfo(String roomNo){
        try {
            return roomService.queryRoomDetails(roomNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *
     * 功能描述：修改房间信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:49
     */
    @RequestMapping("updateRoomInfo")
    @ResponseBody
    public JSONObject updateRoomInfo(YlRoom room){
        try {
            return roomService.updateRoomInfo(room);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *
     * 功能描述：删除房间信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:49
     */
    @RequestMapping("deleteRoomInfo")
    @ResponseBody
    public JSONObject deleteRoomInfo(String roomNo){
        try {
            return roomService.deleteRoomInfo(roomNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
